package com.lsh.oms.core.model.order;

import com.alibaba.fastjson.JSON;
import com.lsh.oms.core.model.base.VenderModel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Map;

/**
 * @author peter
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
public class OrderSignDetail extends VenderModel implements Serializable, Comparable<OrderSignDetail> {
    /**
     *
     */
    private static final long serialVersionUID = 5547629993675366506L;

    private Long id;

    private Long receiptOrderId;

    private Integer itemCode;

    private Long skuId;

    private String skuName;

    private BigDecimal saleUnit;

    private BigDecimal qty;

    private BigDecimal realQty;

    private Integer status;

    private String ext;

    private Integer createdAt;

    private Integer updatedAt;

    private Integer zoneId;

    private Integer packageId;

    private BigDecimal price;

    private BigDecimal money;

    private Long itemId;

    private Long tmsId;

    private Integer supplierOrg;

    private Map<String, Object> extendedProperties;

    public Map<String, Object> getExtendedProperties() {
        if (extendedProperties == null) {
            extendedProperties = JSON.parseObject(this.ext);
        }
        return extendedProperties;
    }


    @Override
    public int compareTo(OrderSignDetail orderSignDetail) {
        if (orderSignDetail == null) {
            return 1;
        }
        if (!this.skuId.equals(orderSignDetail.skuId)) {
            return this.skuId.compareTo(orderSignDetail.getSkuId());
        }
        return this.qty.compareTo(orderSignDetail.getQty());
    }

    public Boolean isWeighingGoods() {
        return Integer.valueOf(1).equals(getExtendedProperties().get("is_weighing_goods")) || "1".equals(getExtendedProperties().get("is_weighing_goods"));
    }
}